#include "Platform.h"
#include "RSManager.h"
#include "Box.h"
#include "Sprite.h"
Platform::Platform(Box* box, int space): Object(box)
{
	_startposx =box->_position.x;
	_space=space;
}


Platform::~Platform(void)
{
}
void Platform::init()
{
	_sprite= RSManager::getInstance()->getSprite(PLATFORM);
	delay=0;
	vec=0;
	nextposx= _startposx+_space;
}

void Platform::update(float time)
{
	delay+=time;
	
	if (delay>90)
	{
		delay =0;
		if(_box->_position.x>= nextposx )
			vec= -_box->_v.x;
		if(_box->_position.x<=_startposx)
			vec= _box->_v.x;
		_box->_position.x+=vec;
	}
	
}

void Platform::render()
{
	_sprite->Render(_box->_position);
}